package com.vinyl.font 
{
	import flash.events.Event;
	import com.vinyl.events.DataEvent;
	import com.vinyl.font.FontLoader;
	import flash.events.EventDispatcher;
	
	public class FontProxy extends EventDispatcher
	{
		public var fontLoader:FontLoader;
		public function FontProxy( fl:FontLoader )
		{
			fontLoader = fl;
			fontLoader.addEventListener( Event.COMPLETE, dataEventHandler );
		}
		
		//implements
		public function load():void
		{
			if( !fontLoader.initFlag )
			{
				trace( fontLoader.url + ": has been loaded" );
				fontLoader.load();
			}
			else
			{
				var data = fontLoader;
				dispatchEvent( new DataEvent( { data: data }, DataEvent.GETDATA ) ) ;
			}
		}
		
		private function dataEventHandler(event:Event):void
		{
			fontLoader.removeEventListener( Event.COMPLETE, dataEventHandler );
			var data = fontLoader;
			dispatchEvent( new DataEvent( data, DataEvent.GETDATA ) ) ;
		}
	}
}
